package com.attilax.user;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.attilax.exception.ExUtil;

public class UserSyncTimer {
	public static Logger logger = LoggerFactory.getLogger(UserSyncTimer.class);
	public static void main(String[] args) {
		logger.info(" ****UserSyncTimer main exed" );
		TimerTask task = new TimerTask() {

			@Override
			public void run() {
				System.out.println("ffff");
				UserSync4jonlye.main(null);

			}
		};

		try {
			long period = 24 * 60 * 60 * 1000;
			// 规定的每天时间15:33:30运行
			final String time = "12:30:00";
			final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd " + time);
			Date firsttime;

			// 首次运行时间
			firsttime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(sdf.format(new Date()));
			// 如果今天的已经过了 首次运行时间就改为明天
			if (System.currentTimeMillis() > firsttime.getTime())
				firsttime = new Date(firsttime.getTime() + period);
			Timer timer = new Timer();
			// 24小时执行1次
			timer.schedule(task, firsttime, period);
			// 24小时执行2次
		//	timer.scheduleAtFixedRate(task, startTime, daySpan);
		} catch (final ParseException e) {
			ExUtil.throwExV2(e);
			e.getStackTrace();
		}

	}

}
